#coding:utf8
from help import * 
import traceback

scroll_str = 'scroll'
pause_str = 'pause'

#config
is_working = False
is_pad = False

kuai_ge_chg=True
shuangJumpLimit=150 #双手鼠标小于此，不跳
shuangJumpLimit_abs=500
jump_qu_interval=1.2
jump_qu_gap=80
no_set_acc_gap = 100
right_jump_thre = 10 #连续多少次使用右手鼠标之后跳跃

shuang_to_kuai_limit=100
qu_jump_limit = 300
liang_conf=[300000,1000000,500] #亮阈值，最大值，消减速度，超过此变非鼠标加速
mouse_speed_gap = [1030,4000]  #第一个值：速度小于此则格子移动；第二个：速度大于此则非格子移动
need_jump_pro = 10  # 此值分之一的概率，双手移动后，再右手移动，产生一个跳跃。0则不跳跃
reset_acc_interval=0.8
left_mouse_delay=0.2
x2_sca_l = [1200,180,180,400,600] #超快，右慢，左慢，左快，右快        
g_ctrl2_enable=False
leftUpGe=1
#格子移动间隔
jump_len = 20
#格子移动速度倍率
jump_scal = 1.2  #右手第一鼠标
jump_scal_sec = 1.2 #右手第二鼠标
jump_scal_left = 0.9 #左手
#间隔移动倍率（越大越慢）
jump_step = 11 #右手
jump_step_left=10 #左手
#间隔移动间隔
jump_du = [2,7,2,5] #右慢，左快，左缓，右缓，左快间隔
jump_left_kuai_gap = 3 #左快下间隔
g_mouse_speed = [10,12,20]

if is_pad:
    jump_step = 7
    jump_step_left=9
    jump_scal = 1.6
    x2_sca_l = [1200,100,100,300,600] 

jump_to_conf = 10
if is_working:
    liang_conf=[500000,1000000,1000]
    jump_qu_gap=100
    jump_left_kuai_gap = 3
    jump_scal = 1.5
    jump_scal_sec = 1.8
    jump_scal_left = 0.8
    jump_step = 10
    jump_step_left=9
    jump_len = 24
    jump_du = [2,7,2,5]

#1366*768
reso_sca = 1  #当屏幕分辨率变化时，可以更改此值
main_win_txt_size = 9 #提示窗口文字大小
cir_para = [17, 20, 3, 1, -15, 4]  #鼠标附近提示圆点。

#2880*1920
# reso_sca = 2
# main_win_txt_size = 10
# cir_para = [17*2+3, 20*2+10, 6, 2, -28, 7]

#几种移动的基本长度单位（像素），比如可以配置为一个手指的宽度。
scroll_len_scal = 80.8*reso_sca
scroll_len_scal_m = {}
screen_gap = 5  #坐标离屏幕边缘的距离

if is_working:
    reso_sca = 1
    scroll_len_scal = (2197-49)/30
    # scroll_len_scal_m = {0:1.25}    
    screen_gap = 20

#各种长度单位距离，包括在初始位置变化角度、用-显示坐标
def get_sc_size():
    return scroll_len_scal_m.get(cfg.cur_screen,1)*scroll_len_scal

screen_idx_default = 1  #找不到鼠标在哪个屏幕，默认返回
lock_l_te = {1:1}  #鼠标在特定屏幕，单步移动距离

ctrl_into_jia = True
mouse_count = [0,1] #添加鼠标的顺序。1左手，0右手，没有为右手
min_d = round(31*reso_sca) #数字坐标间最小距离
wheel_len_scal = 7  #左手滚轮的倍数（距离）
ge_wait_dis_ctrl2 = round(100*reso_sca)  #设置了ge，又按右上按键，超过此距离，开始显示坐标
no_show_dis = round(5*reso_sca) # 设置了ge，小于此距离不显示坐标
sca_l = [1, 0.3,0.1]
max_zi = 60 #最多数字坐标个数
max_l = round(3000*reso_sca) #最大数字坐标长度
main_win_size =  (round(50*reso_sca), round(24*reso_sca))  #提示窗口大小，高度是25时，文字显示会上下动。

screen_start = [[0,0], [-768,-270] ]
screen_start = [[0,0], ]  #决定配置多少个屏幕
screen_size = [[1366,768],[768,1366] ]
screen_icon_size = [[80.8*reso_sca,74*reso_sca],[ (768-359)/5,378/5 ]] #几种移动的基准单位（像素）

last_sign_size = 600*reso_sca #坐标长度超过此数，显示亮黄底色。
enter_gap = 80*reso_sca #not show  enter方向组合键，坐标间距
enter_ge = 2  #enter方向组合键，显示坐标长度
enter_gap2 = 100*reso_sca # +方向组合键，坐标间距
minu_gap_ge = 2 #- 触发显示坐标，坐标个数

ge_m = {
    0:[0,0,0,50],
    1:[400,1,200,10],
    2:[600,1,300,10],
    3:[800,1,400,15],
    4:[1200,1,600,15],    
    5:[2000,1,1000,15],    
    }
ge_m_default = [3000,1,1500,25]
ini_pos = [round(1169*reso_sca),round(57*reso_sca)] #提示窗初始位置

auto_size = True
auto_size_sca = [1,1]
jump_fan = (round(5*reso_sca),round(reso_sca*10))

if is_working:    
    screen_idx_default = 0
    # lock_l_te = {0:2}
    mouse_count = [0,1]
    jump_fan = (8,10)
    auto_size = True
    auto_size_sca = [1,1]
    enter_gap2 = 180 # +方向组合键，坐标间距
    last_sign_size = 900 #坐标长度超过此数，显示亮黄底色。
    wheel_len_scal = 10    
    max_zi = 120
    max_l = 8000    
    main_win_size =  (50, 26)
    cir_para = [18, 23, 3, 1, -15, 4]
    ini_pos = [-200,50]

    screen_start = [[0,0], [2560,-586] ]
    screen_size = [[2560,1440],[1440,2560] ]
    screen_icon_size = [ [(2197-49)/30,1440/18.5],[1440/18.5,(2197-49)/30] ]
    

    screen_start = [[0,0], [2560,0] ]
    screen_size = [[2560,1440],[2560,1440]]
    screen_icon_size = [ [(2197-49)/30,1440/18.5], [(2197-49)/30,1440/18.5]]    
    main_win_txt_size = 10        
    ge_m = {
    0:[0,0,0,50],
    1:[400,1,200,15],
    2:[600,1,300,20],
    3:[800,1,400,25],
    4:[1200,1,600,25],    
    5:[2000,1,1000,25],    
    6:[3200,1,1600,25],    
    }
    ge_m_default = [4000,1,2400,min_d//reso_sca+2]
    
type_m = {}    
def do_type_reload():
    global type_m
    try:
        f = open('type.json')
        type_m = json.load(f)
        f.close()        
        print('load type json',type_m)
    except:
        print('load type json fail')
        type_m = {}
do_type_reload()
def do_type(s):    
    m = {'0.1':'abc',
         '0.2':'aaa',}
    m = type_m
    if s in m:
        pyautogui.write(m[s], interval=0)    

if auto_size:
    import win32api
    import ctypes    
    screen_start = []
    screen_size = []
    ms = win32api.EnumDisplayMonitors()
    print('ms',ms)   
    co =0
    def cha(aa):
        l = []
        for i in aa:
            l.append(round(i*auto_size_sca[co]))
        return l
    
    for i in ms:               
        a,b,c,d = cha(i[2])
        co += 1
        screen_start.append((a,b))
        screen_size.append( (c-a,d-b))
    print('screen',screen_start,screen_size)

x_cancel_gap = 0.5  #左手鼠标按键超时时长
x2_delay = 0.8 #x2 mode取消时，提示图标消失延迟
x2_delay2 = 0 #x2 mode取消时，微调模式图标出现延迟
min_d_mouse = min_d-1  #数字坐标距离鼠标箭头最小距离
scroll_len = 3  #不显示坐标时，按scroll，显示几个坐标
ctrl_double_gap = 0.02
x2_no_effect_len = 3 #坐标少于等于此，按左上增加x2_no_effect_add坐标
x2_no_effect_add = 3

xing_no_effect_len = 0 #坐标少于等于此，数字为0，按* xing_no_effect_add坐标
xing_no_effect_add = 6

er_zi_len = 5  # 最多可以强制固定坐标个数
ge_wait_dis = 2*min_d 

alt_fix_y = True
dst_arr = 'cursor/aero_pin_xl.cur'
dst_arr = 'cursor/aero_up_l.cur'
icon_file_path_force = 'cursor/aero_ew_xl.cur' 
icon_file_path_wait = 'cursor/aero_move_xl.cur' 
icon_file_path_show = 'cursor/aero_up_xl.cur' 
icon_file_path_noshow = 'cursor/aero_arrow_xl.cur' 
icon_file_path_wen = 'cursor/aero_helpsel_xl.cur' 
icon_file_path_bian = 'cursor/aero_pin_xl.cur' 

move_task_delay1 = 0.1 #鼠标触发移动延迟
move_task_delay2 = 0.12 #x2 mode下鼠标触发移动延迟

to_lap = 0.3
show_arr_time = 0.1 #提示窗刷新位置延迟
keep_alive_time = 600  #程序自动关闭

du_refresh_interval = 0.05
len_refresh_interval = 0.4

lock_l = [1, 0.5,3 ,10] #单步移动模式速度，可添加。第一个固定为1
lock_step_default = 1 #默认移动速度，是上面列表的位置序号

sum_max_l = 6 #倍数数字最大长度
draw_txt_yAdd = round(10*reso_sca) # 画数字坐标时，文字上下偏移
draw_txt_txtSize = round(16*reso_sca)  #数字坐标数字大小
draw_txt_pathSize = round(6*reso_sca)   #数字坐标边缘大小
draw_txt_pathSize2 = round(8*reso_sca)   #数字坐标边缘大小

draw_cir_out_width = round(8*reso_sca) #圆圈外圈宽度
draw_cir_out_rad = round(5*reso_sca) #圆圈外圈半径
draw_cir_in_width = round(3*reso_sca) #圆圈内圈宽度
draw_cir_in_rad = round(5*reso_sca) #圆圈内圈半径

txt_win_size = (round(60*reso_sca), round(30*reso_sca)) #数字坐标窗口大小
txt_gap = round(10*reso_sca)  #数字坐标在窗口中的偏移
cir_win_size = (round(60*reso_sca), round(30*reso_sca)) #圆圈窗口大小
cir_gap = round(10*reso_sca) #圆圈在窗口中的偏移

main_win_border = 1*reso_sca # 提示窗口边框大小

small_win_trans = True #数字坐标窗口和圆圈窗口是否透明，试验大小时可以改成false
pos_json_path = 'pos.json' #点位坐标文件路径
resize_cycle = 100 #自动调整提示窗大小周期

##### end of config

screen_config_for_indx = []  #绝对尺寸
screen_config = []  #边缘处理
for i in range(len(screen_start)):
    x,y = screen_start[i]
    w,h = screen_size[i]
    screen_config_for_indx.append([x,y,x+w-1,y+h-1] )
    screen_config.append([x,y,x+w-1-screen_gap,y+h-1-screen_gap] )

def get_mid_suo_scale():
    return 20

def is_jump_base():
    if cfg.isShow or cfg.force_show or cfg.w2showing or cfg.min_ge!=0 or cfg.move_task != None:
        return True
    return False
            
def get_x2_d_sca(isLeft):
    d = cal_dis ((cfg.snap[-1][1], cfg.snap[-1][2]), (cfg.snap[0][1], cfg.snap[0][2]))
    if cfg.middle_pressed:
        cfg.middle_pressed_other = True
    if pm.scroll_pressed:
        pm.scroll_other = True
    si = False
    if cfg.x2_pressed and cfg.has_update_cancle and not cfg.x2_ini_x2_mode:     
        if not cfg.has_update_has_wheel:
            cfg.has_update_cancle_counter = True           
        si = True
    if cfg.x2_pressed and not cfg.x2_pressed_then_other:
        cfg.x2_pressed_then_other = True
        cfg.x2_mode_slow = True
    if cfg.middle_pressed:
        return x2_sca_l[0]/d
    
    if pm.ctrl_pressed or cfg.middle_pressed or si or cfg.x2_mode_slow or pm.scroll_pressed:
        if isLeft:
            return x2_sca_l[2]/d
        return x2_sca_l[1]/d
    if isLeft:
        return x2_sca_l[3]/d
    return x2_sca_l[4]/d

def get_near_count(d,en):    
    if cfg.show_mode==0:
        return 0
    if cfg.show_mode==1:
        return 1
    return 2
g_d=0
def get_far_count(d,en,st):
    global g_d
    if abs(d-g_d)<10:
        d=g_d
    else:
        g_d = d
    if cfg.show_mode==0:
        return 1
    if cfg.show_mode==1:
        return 2
    if d < 70:
        return 4
    return 3

def add_idx(en,st, d,last):    
    if cfg.show_mode<=1:
        return 0,0
    ll = 2
    if  st-en>=4:
        if st-en==4:
            ll = 1    
        if (st+en)%2==0:
            x = (st+en)//2-1
            if last>x:
                return x+1,ll
            return x,ll
        
        x = (st+en+1)//2-1
        if last>x:
            return x+1,ll
        if last<x:
            return x-1,ll       
        return x,ll             
    return 0, 0

def get_scroll_sca():
    if cfg.to<600:
        return 200
    if cfg.to<1000:
        return 250
    return 300

def get_suo_di():
    return 13
    if cfg.to<300:
        return 20
    if cfg.to<1000:
        return 25
    return 30

def get_to_sca():
    if cfg.to < 100:
        return 15
    if cfg.to<300:
        return 20
    if cfg.to<1000:
        return 25
    return 30
    
def get_cur_pos():
    a = mouse.Controller().position
    if type(a) != type((0, 0)):
        return cfg.fix_pos
    if len(a) != 2:
        return cfg.fix_pos
    return a

def set_ge_dis():
    a,b,c,dis =  ge_m.get(cfg.min_ge,ge_m_default)
    cfg.ge_wait_dis2 = dis

def ge_add_xing(a):
    cfg.show_mode = 2
    cfg.left_to_x2 = True    
    cfg.min_ge_has_refresh = False
    cfg.min_ge = a+1
    set_ge_dis()

def ge_set(a):    
    cfg.min_ge_has_refresh = False
    cfg.min_ge = a
    set_ge_dis()

def ge_add_x2(a):    
    cfg.show_mode = 2
    cfg.left_to_x2 = True    
    cfg.min_ge_has_refresh = False
    if a==0:
        cfg.min_ge = 3
    elif a==4:
        cfg.min_ge=7
    elif a==5:
        cfg.min_ge=7
    else:
        cfg.min_ge = a+1
    set_ge_dis()    

def ge_add_ctrl(a):    
    cfg.show_mode = 2
    cfg.left_to_x2 = True    
    cfg.min_ge_has_refresh = False
    if a in (1,3):
        cfg.min_ge = a+1
    elif a==5:
        cfg.min_ge=6
    else:
        cfg.min_ge = a+2
    set_ge_dis()    

def get_ge(d):
    a,b,c,dis =  ge_m.get(cfg.min_ge,ge_m_default)
    a *= reso_sca
    c *= reso_sca
    dis *= reso_sca
    if ge_wait_dis<=min_d or d>=ge_wait_dis:        
        return a,b
    x = c+ (a-c)*d/ge_wait_dis
    return float(x),b    
def clear_max_speed(start=False):
    from routin_base import is_qu
    cfg.jump_add=0
    cfg.max_speed=0
    cfg.has_gap=False
    cfg.slow_start_time=0
    if is_qu() and not start and cfg.left_jump_can_chg:
        cfg.left_jump=True
def clear_sign():
    cfg.left_sign=1
    cfg.left_sign2=1
    cfg.right_sign=1
    cfg.man_sign=1
    cfg.eg_from_mid=False

def set_kuai(a):
    if cfg.jump_kuai != a:
        cfg.jump_kuai = a
        cfg.twh_dx=1000000000

def clear_jump(toclear=True):
    set_kuai(0)
    cfg.jump_state = 0
    cfg.last_move_is_right_solo=False
    clear_sign()
    cfg.mouse_track2_on=False
    cfg.mouse_track_on=False
    clear_max_speed()
    cfg.mouse_track2_has_left=False
    cfg.jump_to=0
    cfg.jump_dx = [0,0]    
    cfg.no_left_move = False
    cfg.can_break=False
    cfg.jump_from_click = True
    cfg.left_mouse_time=0
    if toclear:
        cfg.right_mouse_time=0
    cfg.first_left_time=0
    cfg.first_right_time=0

def clear_acc(toclear=True):
    if not toclear:
        return
    from routin_base import set_no_acc,set_acc,acc_down
    a = random.randint(0,10)
    b = random.randint(0,100)
    cfg.acc_no_reset=False
    if not cfg.mouse_tip_no_show or cfg.force_acc or cfg.w2showing:
        cfg.acc_no_reset=True
        cfg.can_set_acc=True
    else:
        cfg.can_set_acc=False
    set_acc()
    acc_down(True)

def cal_sup_ran():
    cfg.sup_ran=random.randint(7,9)

def clear(pos, clearLock=True):        
    from routin_base import clear_sca,clear_add_show,clear_lock,set_cfg_sum_0,\
            clear_mouse_mode
    if cfg.w2showing:
        cfg.clear_time2 = time.time()
        print('clear time',cfg.clear_time2)
    cal_sup_ran()
    cfg.mouse_p_on = False
    cfg.twh_can_reset=True
    cfg.right_hou_pressed = False    
    clear_acc(clearLock)
    cfg.an_mode=False
    cfg.left_jump=False
    cfg.jump_add=0
    cfg.mouse_speed=0
    clear_jump(clearLock)  
    cfg.getokuai=True
    cfg.keep_qu=False
    cfg.keep_qu_dx=0
    cfg.left_to_x2 = False
    cfg.to_time = 0
    cfg.to_change_time = 0
    cfg.showCut = True    
    cfg.w2_last_ge = 0
    cfg.w2_last_to = 0
    cfg.w2_last_dis = 0
    cfg.last_ge = 0
    cfg.w2_min_ge = 0    
    cfg.to = 0  
    cfg.lock_xing_mode_one_time=False
    cfg.isShow = False
    cfg.show_mode_plus = 0    
    clear_add_show()    
    set_cfg_sum_0()
    clear_sca()
    cfg.force_show = False
    clear_mouse_mode()
    cfg.clear_time = time.time()
    cfg.fix_scroll = 0    
    cfg.manu_add = 0    
    cfg.min_ge = 0
    cfg.min_ge_has_refresh = False
    cfg.min_ge_force_show = False
    cfg.min_ge_force_not_show = False
    cfg.scroll_one = 0    
    cfg.show_jiao = False
    cfg.show_mode = 1
    cfg.add_show2=set()
    cfg.last_xy_float = (0,0)
    cfg.sca_noshow_last = False
    cfg.lock_keep_step = False    
    cfg.is_suo_middle = False
    cfg.w3con = resize_cycle-2
    cfg.is_after_man = False
    cfg.need_jump=False
    cfg.left_jump_can_chg = True
    cfg.show_ff=False
    cfg.eg_from_mid=False    
    twh_clear()
    cfg.twh_has_turn=0
    cfg.tt_has_left=False

    if not cfg.acc_has_left:
        cfg.acc_co+=1
    else:
        cfg.acc_co=0
    cfg.acc_has_left=False
    
    if  time.time()-cfg.last_m_time>0.05:
        cfg.last_m_time = 0

    if clearLock:
        clear_lock()
    if pos:
        cfg.fix_pos = get_cur_pos()
def twh_clear():
    cfg.track_has_wheel=False
    cfg.twh_on=False
    cfg.twh_start_state=False
    cfg.twh_has_wheel=False
    cfg.twh_has_left=False
    cfg.twh_has_right=False
    cfg.twh_last_is_left=False
    cfg.twh_dx=0
class Cg():
    def __init__(self) -> None: 
        self.tt_has_left=False
        self.tt_co=0
        self.j_p = (0,0)
        self.ctrlcap=False
        self.mouse_speed_bk=0
        self.mouse_p_enable=True
        self.right1_mouse_time=0
        self.mouse_p_last_pos = (0,0)
        self.supress=False
        self.jump_thre = 80
        self.stop_jump = [0,0]
        self.last_ig_time = 0
        self.twh_can_reset=True
        self.twh_last_is_left=False
        self.twh_has_turn=0
        self.eg_from_mid=False       
        self.ori_kuai=0
        self.show_ff=False           
        self.left_sc_time=0
        self.right_sign=1
        self.jump_add=0
        self.left_jump_can_chg = True
        self.left_jump=False
        self.an_mode=False
        self.track_dx=[0,0,0,0]
        self.track_dx_abs=0
        self.track_has_shuang=False

        self.twh_dx=0
        self.twh_start_time=0
        self.track_has_wheel=False
        self.twh_on=False
        self.twh_start_state=False
        self.twh_has_wheel=False
        self.twh_has_left=False
        self.twh_has_right=False
        self.twh_right_time=0
        self.twh_left_time=0



        self.track_start_pos = (0,0)
        self.qian_other=False
        self.has_gap=False
        self.slow_start_time=0
        self.max_speed=0
        self.need_jump_co=0
        self.need_jump=False
        self.mouse_speed=0
        self.is_after_man = False
        self.acc_add=0
        self.sup_ran=100
        self.acc_no_reset=False
        self.mid_co=0
        self.x2_co=0
        self.to_co=0
        self.jump_kuai=0
        self.acc_co=0
        self.acc_has_left=False
        self.g_is_acc = -1
        self.acc_speed = 0
        self.acc_speed_co = 0
        self.right_hou_pressed = False
        self.right_hou_has_other=False
        self.right_hou_dx=0
        self.right_hou_time=0
        self.force_acc=True
        self.can_set_acc=False
        self.last_move_is_right_solo=False
        self.mouse_track2_on = False
        self.mouse_track2_has_left=False
        self.mouse_track_on=False
        self.mouse_track_has_right=False
        self.mouse_track_start_time=0
        self.jump_clear=False
        self.jump_from_click = True
        self.can_break=False #慢速模式下，左手大距离移动
        self.jump_len = jump_len
        self.jump_left_pos = [0,0]       
        self.left_sign = 1
        self.left_sign2 = 1
        self.jump_state = 0
        self.jump_dx = [0,0]
        self.jump_dx_o=[0,0]
        self.jump_need_2=False
        self.cur_screen = 0
        self.release_job = 0
        self.press_job = 0
        self.enable_jump_task = False
        self.no_left_move = False
        self.jump_task = None
        self.w3con = 0
        self.left_right_time=0
        self.left_left_time=0
        self.show_mode_plus = 0
        self.ctrl2_job=False
        self.ctrl2_other=False
        self.ctrl2_time = 0
        self.left_to_x2 = False
        self.x2_mode_slow = False
        self.x2_ini_x2_mode = False
        self.x2_ini_mouse=0 #left 1 right 2
        self.suo_middle_to_scal = False
        self.suo_middle_exit_co =0
        self.w2showing_for_suo=False
        self.zi_no_color=0
        self.far=['1',0,0]
        self.has_show_sca = False
        self.ctrl_job = None
        self.ctrl_job_time = 0
        self.has_update=False
        self.has_update_cancle =False
        self.has_update_cancle_counter =False
        self.has_update_has_wheel =False
        self.disable_auto_jump = True

        self.left_mid_time=0
        self.x_press_time = 0
        self.mouse_tip_no_show = True   #起手时，是否显示鼠标提示点
        self.force_tip_no_show = False  #强制显示时，是否显示鼠标提示点
        self.offMid = True
        self.do_mid_task = False
        self.ignMid = False
        self.w2_last_max_ge = 0
        self.x2_mode_start_posp = (0,0)
        self.x2_mode_dd = 0
        self.last_xy_float = (0,0)
        self.capsShow =False
        self.ge_wait_dis2 = min_d
        self.middle_pressed = False
        self.middle_pressed_other = False
        self.w2_last_move = (0,0)
        self.show_mode = 0        
        self.last_m_time = 0
        self.show_state = False
        self.show_last_m = False
        self.show_jiao = False
        self.enter_pressed_seq = []
        self.enter5_du = 0
        self.enter5_len = 0        
        self.scroll_one = 0
        self.min_ge_force_not_show = False
        self.min_ge_has_refresh = False
        self.min_ge_force_show = False        
        self.min_ge = 0
        self.to_exit = False
        self.alt_mode = 0
        self.alt_mode_other = False

        self.manu_add = 0
        self.add_show=[] 
        self.add_show2=set()         
        self.last_m = (0,0)
        self.last_sum = 0
        self.last_active_time = 0
        self.pause_mode = True
        self.maxi = 0
        self.fix_scroll = 0
        self.clear_time = 0
        self.clear_time2 = 0
        self.mouse_mode = 0
        self.mouse_mode4_pos = (0,0)
        self.mouse_mode4_right_time = 0
        self.mouse_m_left_start_time = 0        
        self.mouse_m_left_dis = [0, 0]
        self.mouse_m_right_dis = [0, 0]
        self.mouse_m_left_fix_time = 0
        self.mouse_m_left_fix_pos = [0, 0]
        self.mouse_m_left_max = [0, 0]        
        
        self.x2_mode = False
        self.x2_mode_start_pos = (0,0)
        self.x2_mode_exit_time = 0
        self.x2_mode_d = 100
        self.x2_mode_dst = [0, 0]
        
        self.w2_last_dis = 0 # to 不变时，到fix_pos 的距离
        self.w2_last_to = 0
        self.w2_last_ge=0
        self.w2_min_ge=0
        
        self.last_ge = 0  # 上次显示的坐标图标个数,不包括0        
        self.to = 0
        self.to_time = 0        
        self.always_show_one = True #禁止起手方式显示坐标
        self.reset_show_one = False
        self.force_show = False
        self.fix_pos = (0, 0)  #起始位置
        self.isShow = False #是否显示
        self.showCut = True
        self.sum = '0' #倍数

        self.move_task = None #sum不为0，移动鼠标，产生移动任务
        self.move_task_time = 0
        self.last_move_time = 0  #上次鼠标移动的时间。检测鼠标移动停顿，再执行移动任务。
        self.click_time = -1 #点击任务
        self.click2_time = -1 #双击任务
        self.set_fix_time = 0 #移动后，设置起始位置，并设置此时间。用来处理移动出屏幕范围的情况。
        self.is_pressed = False  #左键是否按下
        self.last_mouse_pos = (0, 0)  #键盘操作时鼠标的位置。移动任务需要。
        
        self.lock = False #数字键盘用来单步移动。
        self.lock_xing_mode = 0  # no 0,* 1 ,+ 2

        self.lock_keep_step = False
        self.lock_keep_step_ori = False

        self.lock_xing_last_move = 4
        self.xing_chu = False
        self.left_mouse = []
        self.right_mouse = []
        self.lock_step = lock_step_default #单步移动的速度。
        self.du_step = 0
        self.sca = 0  #微调角度的比例
        self.sca_du = 0 #微调角度上次剩余的度数
        self.sca_cur = 0 #微调角度固定点的度数
        self.sca_cur_pos = (0, 0) #微调角度固定点的位置
        self.sca_start_pos = (0, 0) #微调角度开始时的位置
        self.pause_key = True #pause按下变换此值，用来隐藏窗口。
        self.pause_move = None #双击pause键，产生移动任务
        self.ctrl_l_time = 0 #左ctrl按下时间，用来判断双击。
        self.conkey=''
                          
        self.real_mouse_time = 0
        self.is_suo = False
        self.is_suo_middle = False
        self.suo_middle_pos = (0,0)
        self.suo_middle_start_pos = (0,0)
        self.suo_middle_to = 0
        self.suo_middle_du = 0

        self.suo_dis = 0
        self.suo_to = 0
        self.to_change_time = 0
        self.x2_pressed = False
        self.x2_type = 0
        self.x2_pressed_then_other =False        
        self.move_to_win = False
        self.show_one_onetime = False
        self.lock_xing_mode_one_time=False
        self.cmd_mode =False         
        self.set_mode = False
        self.set_mode_min = False
        self.pos_m = {}
        self.key_input_time = 0
        self.show_one_on = self.always_show_one
        self.show_mouse_tip = False  #起手前，是否显示鼠标提示点        
        self.w2showing = False
        self.w2snap = []
        self.snap = []
        self.left_mouse_time = 0    
        self.right_mouse_time = 0     
        self.sca_noshow_last = False
        self.last_has_color = False        
        self.show_pos = False       
        self.auto_to_scale = False #反方向移动鼠标，自动进入角度微调模式
        self.draw_set=set()
        self.first_right_time=0
        self.first_left_time=0
        self.jump_to=0
        self.man_has_left=False
        self.man_has_right=False
        self.pause_time=0
        self.last_is_sec_right=False
        self.qian_pressed=False
        self.keep_qu=False  #按模式下，右手移动后，再接左手是快是慢
        self.keep_qu_dx=0   
        self.keep_qu_cancle=False        
        
        self.getokuai=True
        self.man_sign=1
        self.mv_after_wheel=0

cfg = Cg()

class PressMode():
    def __init__(self) -> None:        
        self.add = False
        self.enter = False
        self.scroll = False
        self.alt = False
        self.ctrl =False
        self.ctrl_alt =False

        self.add_main =False        
        self.add_other =False        

        self.enter_main =False
        self.enter_other = False

        self.scroll_main =False
        self.scroll_other =False
        self.scroll_other_mid =False
        self.scroll_re_time=0
        self.scroll_re_dx=0

        self.alt_main = False
        self.alt_on_ctrl =False
        
        self.ctrl_lock = False        
        self.ctrl_main =False

        self.add_pressed = False
        self.enter_pressed = False
        self.scroll_pressed = False
        self.ctrl_pressed = False
        self.ctrl_any_other = False
        self.ctrl_other =False
        self.ctrl_has_chu = False
        self.ctrl_co=0
        self.alt_pressed =False
        self.cap_pressed = False
        self.cmd_pressed = False
        self.cmd_time = 0

    def get_mode(self):
        if self.add:
            return 1
        if self.enter:
            return 2
        if self.scroll:
            return 3
        if self.ctrl:
            return 4
        if self.alt:
            return 5
        if self.ctrl_alt:
            return 6
        return 0
                
    def clearMode(self):
        self.add = False
        self.enter = False
        self.scroll = False
        self.alt = False
        self.ctrl =False
        self.ctrl_alt =False

    def noMode(self):
        if self.add == False and \
        self.enter == False and \
        self.scroll == False and \
        self.alt == False and \
        self.ctrl == False and \
        self.ctrl_alt == False:
            return True
        return False
pm = PressMode()